//
//  LX_TabBar_Controller.swift
//  swiftWeiBo
//
//  Created by 轩 on 16/7/18.
//  Copyright © 2016年 KXuan. All rights reserved.
//

import UIKit

class LX_TabBar_Controller: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //设置tabbar的字体样式
        self.setTabBarItemStyle()
        //创建子控制器
        self.createChildViewControllers()
    }
    
    ///设置tabbar的字体样式
    func setTabBarItemStyle() ->Void{
        
        let globalTabBarItem = UITabBarItem.appearance()
        globalTabBarItem.setTitleTextAttributes(
            [
                NSFontAttributeName:UIFont.systemFontOfSize(14),
                NSForegroundColorAttributeName:UIColor.grayColor()
            ],
            forState: UIControlState.Normal)
        
        globalTabBarItem.setTitleTextAttributes(
            [
                NSForegroundColorAttributeName:UIColor.orangeColor()
            ]
            , forState: UIControlState.Selected)
        
        //设置自定义的tabbar
        let LXTabBar:LX_TabBar = LX_TabBar()
        self.setValue(LXTabBar, forKey: "tabBar")
        LXTabBar.composeContent = {
            //我在控制器赋值了tabbarView的闭包
            //modal出发布内容界面。
            let sendWeiBoVC = LX_SendWeiBo_ViewController()
            self.presentViewController(sendWeiBoVC, animated: true, completion: { () -> Void in
                
            })
//            print("heheh")
        }
        
    }
    
    ///创建子控制器
    func createChildViewControllers() ->Void{
        self.addChildViewController(childVC: LX_Navigation_Controller(rootViewController: LX_Home_TableViewController()), title: "首页", imageName: "tabbar_home", selectImageName: "tabbar_home_selected")
        
        self.addChildViewController(childVC: LX_Navigation_Controller(rootViewController: LX_Message_TableViewController()), title: "消息", imageName: "tabbar_message_center", selectImageName: "tabbar_message_center_selected")
        
        self.addChildViewController(childVC: LX_Navigation_Controller(rootViewController: LX_DisCover_TableViewController()), title: "发现", imageName: "tabbar_discover", selectImageName: "tabbar_discover_selected")
        
        self.addChildViewController(childVC: LX_Navigation_Controller(rootViewController: LX_Profile_TableViewController()), title: "我", imageName: "tabbar_profile", selectImageName: "tabbar_profile_selected")
    }
    
    
    ///添加子控制器
    func addChildViewController(childVC childVC: UIViewController,title:String,imageName:String,selectImageName:String) ->Void{
        //之所以没有title是因为传进来的vc是一个导航控制器。不能
        childVC.tabBarItem.title = title
        childVC.tabBarItem.image = UIImage(named: imageName)
        let selectImage = UIImage(named: selectImageName)
        childVC.tabBarItem.selectedImage = selectImage?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        self.addChildViewController(childVC)
    }
    
    


}
